package com.koala.common.security.component;

import com.koala.common.security.exception.KoalaAuth2Exception;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

import java.io.IOException;

public class KoalaAuth2ExceptionSerializer extends StdSerializer<KoalaAuth2Exception> {

    protected KoalaAuth2ExceptionSerializer() {
        super(KoalaAuth2Exception.class);
    }

    @Override
    public void serialize(KoalaAuth2Exception value, JsonGenerator gen, SerializerProvider provider) throws IOException {
        gen.writeStartObject();
        gen.writeObjectField("code", 1);
        gen.writeStringField("msg", value.getMessage());
        gen.writeStringField("data", value.getErrorCode());
        gen.writeEndObject();
    }
}
